{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:12.021241Z",
     "start_time": "2024-09-26T13:30:12.016561Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from datetime import date\n",
    "import matplotlib.pyplot as plt"
   ],
   "outputs": [],
   "execution_count": 17
  },
  {
   "cell_type": "code",
   "id": "4071cd18702b43b4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:13.712449Z",
     "start_time": "2024-09-26T13:30:12.021241Z"
    }
   },
   "source": [
    "# 训练集\n",
    "train_LogInfo = pd.read_csv('PPD_LogInfo_3_1_Training_Set.csv', encoding='gbk')\n",
    "train_Master = pd.read_csv('PPD_Training_Master_GBK_3_1_Training_Set.csv', encoding='gbk')\n",
    "train_Userupdate = pd.read_csv('PPD_Userupdate_Info_3_1_Training_Set.csv', encoding='gbk')\n",
    "#  测试集\n",
    "test_LogInfo = pd.read_csv('PPD_LogInfo_2_Test_Set.csv', encoding='gbk')\n",
    "test_Master = pd.read_csv('PPD_Master_GBK_2_Test_Set.csv', encoding='gb18030')\n",
    "test_Userupdate = pd.read_csv('PPD_Userupdate_Info_2_Test_Set.csv', encoding='gbk')"
   ],
   "outputs": [],
   "execution_count": 18
  },
  {
   "cell_type": "code",
   "id": "61a29936a352b13c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:13.720998Z",
     "start_time": "2024-09-26T13:30:13.712449Z"
    }
   },
   "source": [
    "test_Userupdate"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx ListingInfo1    UserupdateInfo1 UserupdateInfo2\n",
       "0       10005   2014/02/21       _EducationId      2014/02/16\n",
       "1       10005   2014/02/21         _HasBuyCar      2014/02/16\n",
       "2       10005   2014/02/21  _MarriageStatusId      2014/02/16\n",
       "3       10005   2014/02/21       _MobilePhone      2014/02/16\n",
       "4       10005   2014/02/21       _MobilePhone      2014/02/20\n",
       "...       ...          ...                ...             ...\n",
       "248827   9994   2014/02/28                _QQ      2014/02/20\n",
       "248828   9994   2014/02/28  _ResidenceAddress      2014/02/20\n",
       "248829   9994   2014/02/28    _ResidencePhone      2014/02/20\n",
       "248830   9994   2014/02/28   _ResidenceTypeId      2014/02/20\n",
       "248831   9994   2014/02/28    _ResidenceYears      2014/02/20\n",
       "\n",
       "[248832 rows x 4 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>ListingInfo1</th>\n",
       "      <th>UserupdateInfo1</th>\n",
       "      <th>UserupdateInfo2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10005</td>\n",
       "      <td>2014/02/21</td>\n",
       "      <td>_EducationId</td>\n",
       "      <td>2014/02/16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10005</td>\n",
       "      <td>2014/02/21</td>\n",
       "      <td>_HasBuyCar</td>\n",
       "      <td>2014/02/16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10005</td>\n",
       "      <td>2014/02/21</td>\n",
       "      <td>_MarriageStatusId</td>\n",
       "      <td>2014/02/16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10005</td>\n",
       "      <td>2014/02/21</td>\n",
       "      <td>_MobilePhone</td>\n",
       "      <td>2014/02/16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10005</td>\n",
       "      <td>2014/02/21</td>\n",
       "      <td>_MobilePhone</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248827</th>\n",
       "      <td>9994</td>\n",
       "      <td>2014/02/28</td>\n",
       "      <td>_QQ</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248828</th>\n",
       "      <td>9994</td>\n",
       "      <td>2014/02/28</td>\n",
       "      <td>_ResidenceAddress</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248829</th>\n",
       "      <td>9994</td>\n",
       "      <td>2014/02/28</td>\n",
       "      <td>_ResidencePhone</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248830</th>\n",
       "      <td>9994</td>\n",
       "      <td>2014/02/28</td>\n",
       "      <td>_ResidenceTypeId</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>248831</th>\n",
       "      <td>9994</td>\n",
       "      <td>2014/02/28</td>\n",
       "      <td>_ResidenceYears</td>\n",
       "      <td>2014/02/20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>248832 rows × 4 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 19
  },
  {
   "cell_type": "code",
   "id": "aa4061901a3331f9",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:15.720880Z",
     "start_time": "2024-09-26T13:30:13.720998Z"
    }
   },
   "source": [
    "df_train =  pd.merge(train_Master, train_LogInfo, on='Idx', how='inner')\n",
    "df_train  =  pd.merge(df_train, train_Userupdate, on='Idx',how='inner')"
   ],
   "outputs": [
    {
     "ename": "MemoryError",
     "evalue": "Unable to allocate 10.2 GiB for an array with shape (170, 8084951) and data type int64",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mMemoryError\u001B[0m                               Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[20], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m df_train \u001B[38;5;241m=\u001B[39m  pd\u001B[38;5;241m.\u001B[39mmerge(train_Master, train_LogInfo, on\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mIdx\u001B[39m\u001B[38;5;124m'\u001B[39m, how\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124minner\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[1;32m----> 2\u001B[0m df_train  \u001B[38;5;241m=\u001B[39m  pd\u001B[38;5;241m.\u001B[39mmerge(df_train, train_Userupdate, on\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mIdx\u001B[39m\u001B[38;5;124m'\u001B[39m,how\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124minner\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:183\u001B[0m, in \u001B[0;36mmerge\u001B[1;34m(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)\u001B[0m\n\u001B[0;32m    168\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    169\u001B[0m     op \u001B[38;5;241m=\u001B[39m _MergeOperation(\n\u001B[0;32m    170\u001B[0m         left_df,\n\u001B[0;32m    171\u001B[0m         right_df,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    181\u001B[0m         validate\u001B[38;5;241m=\u001B[39mvalidate,\n\u001B[0;32m    182\u001B[0m     )\n\u001B[1;32m--> 183\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m op\u001B[38;5;241m.\u001B[39mget_result(copy\u001B[38;5;241m=\u001B[39mcopy)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:885\u001B[0m, in \u001B[0;36m_MergeOperation.get_result\u001B[1;34m(self, copy)\u001B[0m\n\u001B[0;32m    881\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_indicator_pre_merge(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright)\n\u001B[0;32m    883\u001B[0m join_index, left_indexer, right_indexer \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_get_join_info()\n\u001B[1;32m--> 885\u001B[0m result \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_reindex_and_concat(\n\u001B[0;32m    886\u001B[0m     join_index, left_indexer, right_indexer, copy\u001B[38;5;241m=\u001B[39mcopy\n\u001B[0;32m    887\u001B[0m )\n\u001B[0;32m    888\u001B[0m result \u001B[38;5;241m=\u001B[39m result\u001B[38;5;241m.\u001B[39m__finalize__(\u001B[38;5;28mself\u001B[39m, method\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_merge_type)\n\u001B[0;32m    890\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mindicator:\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:845\u001B[0m, in \u001B[0;36m_MergeOperation._reindex_and_concat\u001B[1;34m(self, join_index, left_indexer, right_indexer, copy)\u001B[0m\n\u001B[0;32m    837\u001B[0m llabels, rlabels \u001B[38;5;241m=\u001B[39m _items_overlap_with_suffix(\n\u001B[0;32m    838\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft\u001B[38;5;241m.\u001B[39m_info_axis, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright\u001B[38;5;241m.\u001B[39m_info_axis, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msuffixes\n\u001B[0;32m    839\u001B[0m )\n\u001B[0;32m    841\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m left_indexer \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m is_range_indexer(left_indexer, \u001B[38;5;28mlen\u001B[39m(left)):\n\u001B[0;32m    842\u001B[0m     \u001B[38;5;66;03m# Pinning the index here (and in the right code just below) is not\u001B[39;00m\n\u001B[0;32m    843\u001B[0m     \u001B[38;5;66;03m#  necessary, but makes the `.take` more performant if we have e.g.\u001B[39;00m\n\u001B[0;32m    844\u001B[0m     \u001B[38;5;66;03m#  a MultiIndex for left.index.\u001B[39;00m\n\u001B[1;32m--> 845\u001B[0m     lmgr \u001B[38;5;241m=\u001B[39m left\u001B[38;5;241m.\u001B[39m_mgr\u001B[38;5;241m.\u001B[39mreindex_indexer(\n\u001B[0;32m    846\u001B[0m         join_index,\n\u001B[0;32m    847\u001B[0m         left_indexer,\n\u001B[0;32m    848\u001B[0m         axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    849\u001B[0m         copy\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mFalse\u001B[39;00m,\n\u001B[0;32m    850\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    851\u001B[0m         allow_dups\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    852\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    853\u001B[0m     )\n\u001B[0;32m    854\u001B[0m     left \u001B[38;5;241m=\u001B[39m left\u001B[38;5;241m.\u001B[39m_constructor_from_mgr(lmgr, axes\u001B[38;5;241m=\u001B[39mlmgr\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    855\u001B[0m left\u001B[38;5;241m.\u001B[39mindex \u001B[38;5;241m=\u001B[39m join_index\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\managers.py:670\u001B[0m, in \u001B[0;36mBaseBlockManager.reindex_indexer\u001B[1;34m(self, new_axis, indexer, axis, fill_value, allow_dups, copy, only_slice, use_na_proxy)\u001B[0m\n\u001B[0;32m    663\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_slice_take_blocks_ax0(\n\u001B[0;32m    664\u001B[0m         indexer,\n\u001B[0;32m    665\u001B[0m         fill_value\u001B[38;5;241m=\u001B[39mfill_value,\n\u001B[0;32m    666\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39monly_slice,\n\u001B[0;32m    667\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39muse_na_proxy,\n\u001B[0;32m    668\u001B[0m     )\n\u001B[0;32m    669\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 670\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m [\n\u001B[0;32m    671\u001B[0m         blk\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m    672\u001B[0m             indexer,\n\u001B[0;32m    673\u001B[0m             axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    674\u001B[0m             fill_value\u001B[38;5;241m=\u001B[39m(\n\u001B[0;32m    675\u001B[0m                 fill_value \u001B[38;5;28;01mif\u001B[39;00m fill_value \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m blk\u001B[38;5;241m.\u001B[39mfill_value\n\u001B[0;32m    676\u001B[0m             ),\n\u001B[0;32m    677\u001B[0m         )\n\u001B[0;32m    678\u001B[0m         \u001B[38;5;28;01mfor\u001B[39;00m blk \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mblocks\n\u001B[0;32m    679\u001B[0m     ]\n\u001B[0;32m    681\u001B[0m new_axes \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlist\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    682\u001B[0m new_axes[axis] \u001B[38;5;241m=\u001B[39m new_axis\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\managers.py:671\u001B[0m, in \u001B[0;36m<listcomp>\u001B[1;34m(.0)\u001B[0m\n\u001B[0;32m    663\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_slice_take_blocks_ax0(\n\u001B[0;32m    664\u001B[0m         indexer,\n\u001B[0;32m    665\u001B[0m         fill_value\u001B[38;5;241m=\u001B[39mfill_value,\n\u001B[0;32m    666\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39monly_slice,\n\u001B[0;32m    667\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39muse_na_proxy,\n\u001B[0;32m    668\u001B[0m     )\n\u001B[0;32m    669\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    670\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m [\n\u001B[1;32m--> 671\u001B[0m         blk\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m    672\u001B[0m             indexer,\n\u001B[0;32m    673\u001B[0m             axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    674\u001B[0m             fill_value\u001B[38;5;241m=\u001B[39m(\n\u001B[0;32m    675\u001B[0m                 fill_value \u001B[38;5;28;01mif\u001B[39;00m fill_value \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m blk\u001B[38;5;241m.\u001B[39mfill_value\n\u001B[0;32m    676\u001B[0m             ),\n\u001B[0;32m    677\u001B[0m         )\n\u001B[0;32m    678\u001B[0m         \u001B[38;5;28;01mfor\u001B[39;00m blk \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mblocks\n\u001B[0;32m    679\u001B[0m     ]\n\u001B[0;32m    681\u001B[0m new_axes \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlist\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    682\u001B[0m new_axes[axis] \u001B[38;5;241m=\u001B[39m new_axis\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\blocks.py:1061\u001B[0m, in \u001B[0;36mBlock.take_nd\u001B[1;34m(self, indexer, axis, new_mgr_locs, fill_value)\u001B[0m\n\u001B[0;32m   1058\u001B[0m     allow_fill \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m   1060\u001B[0m \u001B[38;5;66;03m# Note: algos.take_nd has upcast logic similar to coerce_to_target_dtype\u001B[39;00m\n\u001B[1;32m-> 1061\u001B[0m new_values \u001B[38;5;241m=\u001B[39m algos\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m   1062\u001B[0m     values, indexer, axis\u001B[38;5;241m=\u001B[39maxis, allow_fill\u001B[38;5;241m=\u001B[39mallow_fill, fill_value\u001B[38;5;241m=\u001B[39mfill_value\n\u001B[0;32m   1063\u001B[0m )\n\u001B[0;32m   1065\u001B[0m \u001B[38;5;66;03m# Called from three places in managers, all of which satisfy\u001B[39;00m\n\u001B[0;32m   1066\u001B[0m \u001B[38;5;66;03m#  these assertions\u001B[39;00m\n\u001B[0;32m   1067\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(\u001B[38;5;28mself\u001B[39m, ExtensionBlock):\n\u001B[0;32m   1068\u001B[0m     \u001B[38;5;66;03m# NB: in this case, the 'axis' kwarg will be ignored in the\u001B[39;00m\n\u001B[0;32m   1069\u001B[0m     \u001B[38;5;66;03m#  algos.take_nd call above.\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\array_algos\\take.py:118\u001B[0m, in \u001B[0;36mtake_nd\u001B[1;34m(arr, indexer, axis, fill_value, allow_fill)\u001B[0m\n\u001B[0;32m    115\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m arr\u001B[38;5;241m.\u001B[39mtake(indexer, fill_value\u001B[38;5;241m=\u001B[39mfill_value, allow_fill\u001B[38;5;241m=\u001B[39mallow_fill)\n\u001B[0;32m    117\u001B[0m arr \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39masarray(arr)\n\u001B[1;32m--> 118\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\array_algos\\take.py:158\u001B[0m, in \u001B[0;36m_take_nd_ndarray\u001B[1;34m(arr, indexer, axis, fill_value, allow_fill)\u001B[0m\n\u001B[0;32m    156\u001B[0m     out \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mempty(out_shape, dtype\u001B[38;5;241m=\u001B[39mdtype, order\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mF\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    157\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 158\u001B[0m     out \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mempty(out_shape, dtype\u001B[38;5;241m=\u001B[39mdtype)\n\u001B[0;32m    160\u001B[0m func \u001B[38;5;241m=\u001B[39m _get_take_nd_function(\n\u001B[0;32m    161\u001B[0m     arr\u001B[38;5;241m.\u001B[39mndim, arr\u001B[38;5;241m.\u001B[39mdtype, out\u001B[38;5;241m.\u001B[39mdtype, axis\u001B[38;5;241m=\u001B[39maxis, mask_info\u001B[38;5;241m=\u001B[39mmask_info\n\u001B[0;32m    162\u001B[0m )\n\u001B[0;32m    163\u001B[0m func(arr, indexer, out, fill_value)\n",
      "\u001B[1;31mMemoryError\u001B[0m: Unable to allocate 10.2 GiB for an array with shape (170, 8084951) and data type int64"
     ]
    }
   ],
   "execution_count": 20
  },
  {
   "cell_type": "code",
   "id": "bb9c199f894c3286",
   "metadata": {},
   "source": [
    "df_train"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "b8886cdc0d76e661",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:37.250747Z",
     "start_time": "2024-09-26T13:30:35.978791Z"
    }
   },
   "source": [
    "df_test =  pd.merge(test_Master, test_LogInfo, on='Idx', how='inner')\n",
    "df_test  =  pd.merge(df_test, test_Userupdate, on='Idx',how='inner')"
   ],
   "outputs": [
    {
     "ename": "MemoryError",
     "evalue": "Unable to allocate 6.77 GiB for an array with shape (169, 5374549) and data type int64",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mMemoryError\u001B[0m                               Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[21], line 2\u001B[0m\n\u001B[0;32m      1\u001B[0m df_test \u001B[38;5;241m=\u001B[39m  pd\u001B[38;5;241m.\u001B[39mmerge(test_Master, test_LogInfo, on\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mIdx\u001B[39m\u001B[38;5;124m'\u001B[39m, how\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124minner\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[1;32m----> 2\u001B[0m df_test  \u001B[38;5;241m=\u001B[39m  pd\u001B[38;5;241m.\u001B[39mmerge(df_test, test_Userupdate, on\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mIdx\u001B[39m\u001B[38;5;124m'\u001B[39m,how\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124minner\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:183\u001B[0m, in \u001B[0;36mmerge\u001B[1;34m(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate)\u001B[0m\n\u001B[0;32m    168\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    169\u001B[0m     op \u001B[38;5;241m=\u001B[39m _MergeOperation(\n\u001B[0;32m    170\u001B[0m         left_df,\n\u001B[0;32m    171\u001B[0m         right_df,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    181\u001B[0m         validate\u001B[38;5;241m=\u001B[39mvalidate,\n\u001B[0;32m    182\u001B[0m     )\n\u001B[1;32m--> 183\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m op\u001B[38;5;241m.\u001B[39mget_result(copy\u001B[38;5;241m=\u001B[39mcopy)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:885\u001B[0m, in \u001B[0;36m_MergeOperation.get_result\u001B[1;34m(self, copy)\u001B[0m\n\u001B[0;32m    881\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_indicator_pre_merge(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright)\n\u001B[0;32m    883\u001B[0m join_index, left_indexer, right_indexer \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_get_join_info()\n\u001B[1;32m--> 885\u001B[0m result \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_reindex_and_concat(\n\u001B[0;32m    886\u001B[0m     join_index, left_indexer, right_indexer, copy\u001B[38;5;241m=\u001B[39mcopy\n\u001B[0;32m    887\u001B[0m )\n\u001B[0;32m    888\u001B[0m result \u001B[38;5;241m=\u001B[39m result\u001B[38;5;241m.\u001B[39m__finalize__(\u001B[38;5;28mself\u001B[39m, method\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_merge_type)\n\u001B[0;32m    890\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mindicator:\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\reshape\\merge.py:845\u001B[0m, in \u001B[0;36m_MergeOperation._reindex_and_concat\u001B[1;34m(self, join_index, left_indexer, right_indexer, copy)\u001B[0m\n\u001B[0;32m    837\u001B[0m llabels, rlabels \u001B[38;5;241m=\u001B[39m _items_overlap_with_suffix(\n\u001B[0;32m    838\u001B[0m     \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mleft\u001B[38;5;241m.\u001B[39m_info_axis, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mright\u001B[38;5;241m.\u001B[39m_info_axis, \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39msuffixes\n\u001B[0;32m    839\u001B[0m )\n\u001B[0;32m    841\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m left_indexer \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m is_range_indexer(left_indexer, \u001B[38;5;28mlen\u001B[39m(left)):\n\u001B[0;32m    842\u001B[0m     \u001B[38;5;66;03m# Pinning the index here (and in the right code just below) is not\u001B[39;00m\n\u001B[0;32m    843\u001B[0m     \u001B[38;5;66;03m#  necessary, but makes the `.take` more performant if we have e.g.\u001B[39;00m\n\u001B[0;32m    844\u001B[0m     \u001B[38;5;66;03m#  a MultiIndex for left.index.\u001B[39;00m\n\u001B[1;32m--> 845\u001B[0m     lmgr \u001B[38;5;241m=\u001B[39m left\u001B[38;5;241m.\u001B[39m_mgr\u001B[38;5;241m.\u001B[39mreindex_indexer(\n\u001B[0;32m    846\u001B[0m         join_index,\n\u001B[0;32m    847\u001B[0m         left_indexer,\n\u001B[0;32m    848\u001B[0m         axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    849\u001B[0m         copy\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mFalse\u001B[39;00m,\n\u001B[0;32m    850\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    851\u001B[0m         allow_dups\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    852\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    853\u001B[0m     )\n\u001B[0;32m    854\u001B[0m     left \u001B[38;5;241m=\u001B[39m left\u001B[38;5;241m.\u001B[39m_constructor_from_mgr(lmgr, axes\u001B[38;5;241m=\u001B[39mlmgr\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    855\u001B[0m left\u001B[38;5;241m.\u001B[39mindex \u001B[38;5;241m=\u001B[39m join_index\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\managers.py:670\u001B[0m, in \u001B[0;36mBaseBlockManager.reindex_indexer\u001B[1;34m(self, new_axis, indexer, axis, fill_value, allow_dups, copy, only_slice, use_na_proxy)\u001B[0m\n\u001B[0;32m    663\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_slice_take_blocks_ax0(\n\u001B[0;32m    664\u001B[0m         indexer,\n\u001B[0;32m    665\u001B[0m         fill_value\u001B[38;5;241m=\u001B[39mfill_value,\n\u001B[0;32m    666\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39monly_slice,\n\u001B[0;32m    667\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39muse_na_proxy,\n\u001B[0;32m    668\u001B[0m     )\n\u001B[0;32m    669\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 670\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m [\n\u001B[0;32m    671\u001B[0m         blk\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m    672\u001B[0m             indexer,\n\u001B[0;32m    673\u001B[0m             axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    674\u001B[0m             fill_value\u001B[38;5;241m=\u001B[39m(\n\u001B[0;32m    675\u001B[0m                 fill_value \u001B[38;5;28;01mif\u001B[39;00m fill_value \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m blk\u001B[38;5;241m.\u001B[39mfill_value\n\u001B[0;32m    676\u001B[0m             ),\n\u001B[0;32m    677\u001B[0m         )\n\u001B[0;32m    678\u001B[0m         \u001B[38;5;28;01mfor\u001B[39;00m blk \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mblocks\n\u001B[0;32m    679\u001B[0m     ]\n\u001B[0;32m    681\u001B[0m new_axes \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlist\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    682\u001B[0m new_axes[axis] \u001B[38;5;241m=\u001B[39m new_axis\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\managers.py:671\u001B[0m, in \u001B[0;36m<listcomp>\u001B[1;34m(.0)\u001B[0m\n\u001B[0;32m    663\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_slice_take_blocks_ax0(\n\u001B[0;32m    664\u001B[0m         indexer,\n\u001B[0;32m    665\u001B[0m         fill_value\u001B[38;5;241m=\u001B[39mfill_value,\n\u001B[0;32m    666\u001B[0m         only_slice\u001B[38;5;241m=\u001B[39monly_slice,\n\u001B[0;32m    667\u001B[0m         use_na_proxy\u001B[38;5;241m=\u001B[39muse_na_proxy,\n\u001B[0;32m    668\u001B[0m     )\n\u001B[0;32m    669\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[0;32m    670\u001B[0m     new_blocks \u001B[38;5;241m=\u001B[39m [\n\u001B[1;32m--> 671\u001B[0m         blk\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m    672\u001B[0m             indexer,\n\u001B[0;32m    673\u001B[0m             axis\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m    674\u001B[0m             fill_value\u001B[38;5;241m=\u001B[39m(\n\u001B[0;32m    675\u001B[0m                 fill_value \u001B[38;5;28;01mif\u001B[39;00m fill_value \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;28;01melse\u001B[39;00m blk\u001B[38;5;241m.\u001B[39mfill_value\n\u001B[0;32m    676\u001B[0m             ),\n\u001B[0;32m    677\u001B[0m         )\n\u001B[0;32m    678\u001B[0m         \u001B[38;5;28;01mfor\u001B[39;00m blk \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mblocks\n\u001B[0;32m    679\u001B[0m     ]\n\u001B[0;32m    681\u001B[0m new_axes \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mlist\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39maxes)\n\u001B[0;32m    682\u001B[0m new_axes[axis] \u001B[38;5;241m=\u001B[39m new_axis\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\internals\\blocks.py:1061\u001B[0m, in \u001B[0;36mBlock.take_nd\u001B[1;34m(self, indexer, axis, new_mgr_locs, fill_value)\u001B[0m\n\u001B[0;32m   1058\u001B[0m     allow_fill \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n\u001B[0;32m   1060\u001B[0m \u001B[38;5;66;03m# Note: algos.take_nd has upcast logic similar to coerce_to_target_dtype\u001B[39;00m\n\u001B[1;32m-> 1061\u001B[0m new_values \u001B[38;5;241m=\u001B[39m algos\u001B[38;5;241m.\u001B[39mtake_nd(\n\u001B[0;32m   1062\u001B[0m     values, indexer, axis\u001B[38;5;241m=\u001B[39maxis, allow_fill\u001B[38;5;241m=\u001B[39mallow_fill, fill_value\u001B[38;5;241m=\u001B[39mfill_value\n\u001B[0;32m   1063\u001B[0m )\n\u001B[0;32m   1065\u001B[0m \u001B[38;5;66;03m# Called from three places in managers, all of which satisfy\u001B[39;00m\n\u001B[0;32m   1066\u001B[0m \u001B[38;5;66;03m#  these assertions\u001B[39;00m\n\u001B[0;32m   1067\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28misinstance\u001B[39m(\u001B[38;5;28mself\u001B[39m, ExtensionBlock):\n\u001B[0;32m   1068\u001B[0m     \u001B[38;5;66;03m# NB: in this case, the 'axis' kwarg will be ignored in the\u001B[39;00m\n\u001B[0;32m   1069\u001B[0m     \u001B[38;5;66;03m#  algos.take_nd call above.\u001B[39;00m\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\array_algos\\take.py:118\u001B[0m, in \u001B[0;36mtake_nd\u001B[1;34m(arr, indexer, axis, fill_value, allow_fill)\u001B[0m\n\u001B[0;32m    115\u001B[0m     \u001B[38;5;28;01mreturn\u001B[39;00m arr\u001B[38;5;241m.\u001B[39mtake(indexer, fill_value\u001B[38;5;241m=\u001B[39mfill_value, allow_fill\u001B[38;5;241m=\u001B[39mallow_fill)\n\u001B[0;32m    117\u001B[0m arr \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39masarray(arr)\n\u001B[1;32m--> 118\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m _take_nd_ndarray(arr, indexer, axis, fill_value, allow_fill)\n",
      "File \u001B[1;32mD:\\Anaconda\\Lib\\site-packages\\pandas\\core\\array_algos\\take.py:158\u001B[0m, in \u001B[0;36m_take_nd_ndarray\u001B[1;34m(arr, indexer, axis, fill_value, allow_fill)\u001B[0m\n\u001B[0;32m    156\u001B[0m     out \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mempty(out_shape, dtype\u001B[38;5;241m=\u001B[39mdtype, order\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mF\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    157\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m--> 158\u001B[0m     out \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mempty(out_shape, dtype\u001B[38;5;241m=\u001B[39mdtype)\n\u001B[0;32m    160\u001B[0m func \u001B[38;5;241m=\u001B[39m _get_take_nd_function(\n\u001B[0;32m    161\u001B[0m     arr\u001B[38;5;241m.\u001B[39mndim, arr\u001B[38;5;241m.\u001B[39mdtype, out\u001B[38;5;241m.\u001B[39mdtype, axis\u001B[38;5;241m=\u001B[39maxis, mask_info\u001B[38;5;241m=\u001B[39mmask_info\n\u001B[0;32m    162\u001B[0m )\n\u001B[0;32m    163\u001B[0m func(arr, indexer, out, fill_value)\n",
      "\u001B[1;31mMemoryError\u001B[0m: Unable to allocate 6.77 GiB for an array with shape (169, 5374549) and data type int64"
     ]
    }
   ],
   "execution_count": 21
  },
  {
   "cell_type": "code",
   "id": "595d5458be355053",
   "metadata": {
    "scrolled": true,
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:41.068404Z",
     "start_time": "2024-09-26T13:30:40.872857Z"
    }
   },
   "source": [
    "df_test"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx  UserInfo_1 UserInfo_2  UserInfo_3 UserInfo_4  WeblogInfo_1  \\\n",
       "0       10005         1.0         广州         5.0         韶关           NaN   \n",
       "1       10005         1.0         广州         5.0         韶关           NaN   \n",
       "2       10005         1.0         广州         5.0         韶关           NaN   \n",
       "3       10005         1.0         广州         5.0         韶关           NaN   \n",
       "4       10013         4.0         郴州         6.0         广州           NaN   \n",
       "...       ...         ...        ...         ...        ...           ...   \n",
       "385875   9994         4.0         上海         5.0         常州           NaN   \n",
       "385876   9994         4.0         上海         5.0         常州           NaN   \n",
       "385877   9994         4.0         上海         5.0         常州           NaN   \n",
       "385878   9994         4.0         上海         5.0         常州           NaN   \n",
       "385879   9994         4.0         上海         5.0         常州           NaN   \n",
       "\n",
       "        WeblogInfo_2  WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  ...  \\\n",
       "0                0.0           NaN           1.0           1.0  ...   \n",
       "1                0.0           NaN           1.0           1.0  ...   \n",
       "2                0.0           NaN           1.0           1.0  ...   \n",
       "3                0.0           NaN           1.0           1.0  ...   \n",
       "4                0.0           NaN           1.0           1.0  ...   \n",
       "...              ...           ...           ...           ...  ...   \n",
       "385875           0.0           NaN           1.0           1.0  ...   \n",
       "385876           0.0           NaN           1.0           1.0  ...   \n",
       "385877           0.0           NaN           1.0           1.0  ...   \n",
       "385878           0.0           NaN           1.0           1.0  ...   \n",
       "385879           0.0           NaN           1.0           1.0  ...   \n",
       "\n",
       "        SocialNetwork_13  SocialNetwork_14  SocialNetwork_15  \\\n",
       "0                      0                 0                 0   \n",
       "1                      0                 0                 0   \n",
       "2                      0                 0                 0   \n",
       "3                      0                 0                 0   \n",
       "4                      0                 0                 1   \n",
       "...                  ...               ...               ...   \n",
       "385875                 0                 0                 0   \n",
       "385876                 0                 0                 0   \n",
       "385877                 0                 0                 0   \n",
       "385878                 0                 0                 0   \n",
       "385879                 0                 0                 0   \n",
       "\n",
       "        SocialNetwork_16  SocialNetwork_17  ListingInfo  Listinginfo1  \\\n",
       "0                      0                 1    21/2/2014    2014-02-21   \n",
       "1                      0                 1    21/2/2014    2014-02-21   \n",
       "2                      0                 1    21/2/2014    2014-02-21   \n",
       "3                      0                 1    21/2/2014    2014-02-21   \n",
       "4                      0                 0    28/2/2014    2014-02-28   \n",
       "...                  ...               ...          ...           ...   \n",
       "385875                 0                 0    28/2/2014    2014-02-28   \n",
       "385876                 0                 0    28/2/2014    2014-02-28   \n",
       "385877                 0                 0    28/2/2014    2014-02-28   \n",
       "385878                 0                 0    28/2/2014    2014-02-28   \n",
       "385879                 0                 0    28/2/2014    2014-02-28   \n",
       "\n",
       "        LogInfo1  LogInfo2    LogInfo3  \n",
       "0              1         2  2014-02-20  \n",
       "1              2        21  2014-02-21  \n",
       "2             -4         6  2014-02-20  \n",
       "3             -4         6  2014-02-20  \n",
       "4            103         6  2014-02-25  \n",
       "...          ...       ...         ...  \n",
       "385875         2        21  2014-02-28  \n",
       "385876         4         1  2014-02-20  \n",
       "385877        -4         6  2014-02-20  \n",
       "385878        -4         6  2014-02-20  \n",
       "385879        -4         6  2014-02-20  \n",
       "\n",
       "[385880 rows x 231 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>UserInfo_1</th>\n",
       "      <th>UserInfo_2</th>\n",
       "      <th>UserInfo_3</th>\n",
       "      <th>UserInfo_4</th>\n",
       "      <th>WeblogInfo_1</th>\n",
       "      <th>WeblogInfo_2</th>\n",
       "      <th>WeblogInfo_3</th>\n",
       "      <th>WeblogInfo_4</th>\n",
       "      <th>WeblogInfo_5</th>\n",
       "      <th>...</th>\n",
       "      <th>SocialNetwork_13</th>\n",
       "      <th>SocialNetwork_14</th>\n",
       "      <th>SocialNetwork_15</th>\n",
       "      <th>SocialNetwork_16</th>\n",
       "      <th>SocialNetwork_17</th>\n",
       "      <th>ListingInfo</th>\n",
       "      <th>Listinginfo1</th>\n",
       "      <th>LogInfo1</th>\n",
       "      <th>LogInfo2</th>\n",
       "      <th>LogInfo3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>广州</td>\n",
       "      <td>5.0</td>\n",
       "      <td>韶关</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>广州</td>\n",
       "      <td>5.0</td>\n",
       "      <td>韶关</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>2014-02-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>广州</td>\n",
       "      <td>5.0</td>\n",
       "      <td>韶关</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>-4</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>广州</td>\n",
       "      <td>5.0</td>\n",
       "      <td>韶关</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>-4</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10013</td>\n",
       "      <td>4.0</td>\n",
       "      <td>郴州</td>\n",
       "      <td>6.0</td>\n",
       "      <td>广州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>103</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385875</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>5.0</td>\n",
       "      <td>常州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2</td>\n",
       "      <td>21</td>\n",
       "      <td>2014-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385876</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>5.0</td>\n",
       "      <td>常州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385877</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>5.0</td>\n",
       "      <td>常州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>-4</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385878</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>5.0</td>\n",
       "      <td>常州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>-4</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385879</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>上海</td>\n",
       "      <td>5.0</td>\n",
       "      <td>常州</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>-4</td>\n",
       "      <td>6</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>385880 rows × 231 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 22
  },
  {
   "cell_type": "code",
   "id": "a173da2bf09b27ea",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:55.048504Z",
     "start_time": "2024-09-26T13:30:51.763974Z"
    }
   },
   "source": [
    "# 分离数值型和字符串型数据\n",
    "numeric_df = df_test.select_dtypes(include=['number'])  # 数值型\n",
    "string_df = df_test.select_dtypes(include=['object'])   # 字符串型\n",
    "\n",
    "# 对数值型数据进行空值填充（例如用均值填充）\n",
    "numeric_df.fillna(numeric_df.median(), inplace=True)\n",
    "\n",
    "# 对字符串型数据进行空值填充（例如用'unknown'填充）\n",
    "string_df.fillna('unknown', inplace=True)\n",
    "\n",
    "# 如果需要将填充后的数据合并回原始数据框\n",
    "df_test = pd.concat([numeric_df, string_df], axis=1)\n",
    "df_test"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
       "0       10005         1.0         5.0           1.0           0.0   \n",
       "1       10005         1.0         5.0           1.0           0.0   \n",
       "2       10005         1.0         5.0           1.0           0.0   \n",
       "3       10005         1.0         5.0           1.0           0.0   \n",
       "4       10013         4.0         6.0           1.0           0.0   \n",
       "...       ...         ...         ...           ...           ...   \n",
       "385875   9994         4.0         5.0           1.0           0.0   \n",
       "385876   9994         4.0         5.0           1.0           0.0   \n",
       "385877   9994         4.0         5.0           1.0           0.0   \n",
       "385878   9994         4.0         5.0           1.0           0.0   \n",
       "385879   9994         4.0         5.0           1.0           0.0   \n",
       "\n",
       "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
       "0                1.0           1.0           1.0           1.0             2   \n",
       "1                1.0           1.0           1.0           1.0             2   \n",
       "2                1.0           1.0           1.0           1.0             2   \n",
       "3                1.0           1.0           1.0           1.0             2   \n",
       "4                1.0           1.0           1.0           1.0             8   \n",
       "...              ...           ...           ...           ...           ...   \n",
       "385875           1.0           1.0           1.0           1.0             4   \n",
       "385876           1.0           1.0           1.0           1.0             4   \n",
       "385877           1.0           1.0           1.0           1.0             4   \n",
       "385878           1.0           1.0           1.0           1.0             4   \n",
       "385879           1.0           1.0           1.0           1.0             4   \n",
       "\n",
       "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
       "0       ...                E                E                E   \n",
       "1       ...                E                E                E   \n",
       "2       ...                E                E                E   \n",
       "3       ...                E                E                E   \n",
       "4       ...                E                E                E   \n",
       "...     ...              ...              ...              ...   \n",
       "385875  ...                E                E                E   \n",
       "385876  ...                E                E                E   \n",
       "385877  ...                E                E                E   \n",
       "385878  ...                E                E                E   \n",
       "385879  ...                E                E                E   \n",
       "\n",
       "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
       "0                     E              D             I5              A   \n",
       "1                     E              D             I5              A   \n",
       "2                     E              D             I5              A   \n",
       "3                     E              D             I5              A   \n",
       "4                     E              I             I4              D   \n",
       "...                 ...            ...            ...            ...   \n",
       "385875                E              I             I5              D   \n",
       "385876                E              I             I5              D   \n",
       "385877                E              I             I5              D   \n",
       "385878                E              I             I5              D   \n",
       "385879                E              I             I5              D   \n",
       "\n",
       "        ListingInfo  Listinginfo1    LogInfo3  \n",
       "0         21/2/2014    2014-02-21  2014-02-20  \n",
       "1         21/2/2014    2014-02-21  2014-02-21  \n",
       "2         21/2/2014    2014-02-21  2014-02-20  \n",
       "3         21/2/2014    2014-02-21  2014-02-20  \n",
       "4         28/2/2014    2014-02-28  2014-02-25  \n",
       "...             ...           ...         ...  \n",
       "385875    28/2/2014    2014-02-28  2014-02-28  \n",
       "385876    28/2/2014    2014-02-28  2014-02-20  \n",
       "385877    28/2/2014    2014-02-28  2014-02-20  \n",
       "385878    28/2/2014    2014-02-28  2014-02-20  \n",
       "385879    28/2/2014    2014-02-28  2014-02-20  \n",
       "\n",
       "[385880 rows x 231 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>UserInfo_1</th>\n",
       "      <th>UserInfo_3</th>\n",
       "      <th>WeblogInfo_1</th>\n",
       "      <th>WeblogInfo_2</th>\n",
       "      <th>WeblogInfo_3</th>\n",
       "      <th>WeblogInfo_4</th>\n",
       "      <th>WeblogInfo_5</th>\n",
       "      <th>WeblogInfo_6</th>\n",
       "      <th>WeblogInfo_7</th>\n",
       "      <th>...</th>\n",
       "      <th>Education_Info4</th>\n",
       "      <th>Education_Info6</th>\n",
       "      <th>Education_Info7</th>\n",
       "      <th>Education_Info8</th>\n",
       "      <th>WeblogInfo_19</th>\n",
       "      <th>WeblogInfo_20</th>\n",
       "      <th>WeblogInfo_21</th>\n",
       "      <th>ListingInfo</th>\n",
       "      <th>Listinginfo1</th>\n",
       "      <th>LogInfo3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>D</td>\n",
       "      <td>I5</td>\n",
       "      <td>A</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>D</td>\n",
       "      <td>I5</td>\n",
       "      <td>A</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>2014-02-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>D</td>\n",
       "      <td>I5</td>\n",
       "      <td>A</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>D</td>\n",
       "      <td>I5</td>\n",
       "      <td>A</td>\n",
       "      <td>21/2/2014</td>\n",
       "      <td>2014-02-21</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10013</td>\n",
       "      <td>4.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I4</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385875</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385876</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385877</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385878</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385879</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>28/2/2014</td>\n",
       "      <td>2014-02-28</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>385880 rows × 231 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 23
  },
  {
   "cell_type": "code",
   "id": "870a1d4f1894af75",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:30:59.836907Z",
     "start_time": "2024-09-26T13:30:59.552868Z"
    }
   },
   "source": [
    "df_test.isnull().sum()"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Idx              0\n",
       "UserInfo_1       0\n",
       "UserInfo_3       0\n",
       "WeblogInfo_1     0\n",
       "WeblogInfo_2     0\n",
       "                ..\n",
       "WeblogInfo_20    0\n",
       "WeblogInfo_21    0\n",
       "ListingInfo      0\n",
       "Listinginfo1     0\n",
       "LogInfo3         0\n",
       "Length: 231, dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 24
  },
  {
   "cell_type": "code",
   "id": "c11d797d241c0753",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:04.498853Z",
     "start_time": "2024-09-26T13:31:01.288509Z"
    }
   },
   "source": [
    "# 分离数值型和字符串型数据\n",
    "numeric_df1 = df_train.select_dtypes(include=['number'])  # 数值型\n",
    "string_df1 = df_train.select_dtypes(include=['object'])   # 字符串型\n",
    "\n",
    "# 对数值型数据进行空值填充（例如用均值填充）\n",
    "numeric_df1.fillna(numeric_df1.median(), inplace=True)\n",
    "\n",
    "# 对字符串型数据进行空值填充（例如用'unknown'填充）\n",
    "string_df1.fillna('unknown', inplace=True)\n",
    "\n",
    "# 如果需要将填充后的数据合并回原始数据框\n",
    "df_train = pd.concat([numeric_df1, string_df1], axis=1)\n",
    "df_train"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
       "0       10001         1.0         4.0           1.0           1.0   \n",
       "1       10001         1.0         4.0           1.0           1.0   \n",
       "2       10001         1.0         4.0           1.0           1.0   \n",
       "3       10001         1.0         4.0           1.0           1.0   \n",
       "4       10001         1.0         4.0           1.0           1.0   \n",
       "...       ...         ...         ...           ...           ...   \n",
       "580546   9998         4.0         5.0           1.0           0.0   \n",
       "580547   9998         4.0         5.0           1.0           0.0   \n",
       "580548   9998         4.0         5.0           1.0           0.0   \n",
       "580549   9998         4.0         5.0           1.0           0.0   \n",
       "580550   9998         4.0         5.0           1.0           0.0   \n",
       "\n",
       "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
       "0                0.0           1.0           1.0           1.0            14   \n",
       "1                0.0           1.0           1.0           1.0            14   \n",
       "2                0.0           1.0           1.0           1.0            14   \n",
       "3                0.0           1.0           1.0           1.0            14   \n",
       "4                0.0           1.0           1.0           1.0            14   \n",
       "...              ...           ...           ...           ...           ...   \n",
       "580546           0.0           1.0           1.0           1.0             3   \n",
       "580547           0.0           1.0           1.0           1.0             3   \n",
       "580548           0.0           1.0           1.0           1.0             3   \n",
       "580549           0.0           1.0           1.0           1.0             3   \n",
       "580550           0.0           1.0           1.0           1.0             3   \n",
       "\n",
       "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
       "0       ...                E                E                E   \n",
       "1       ...                E                E                E   \n",
       "2       ...                E                E                E   \n",
       "3       ...                E                E                E   \n",
       "4       ...                E                E                E   \n",
       "...     ...              ...              ...              ...   \n",
       "580546  ...                E                E                E   \n",
       "580547  ...                E                E                E   \n",
       "580548  ...                E                E                E   \n",
       "580549  ...                E                E                E   \n",
       "580550  ...                E                E                E   \n",
       "\n",
       "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
       "0                     E              I             I5              D   \n",
       "1                     E              I             I5              D   \n",
       "2                     E              I             I5              D   \n",
       "3                     E              I             I5              D   \n",
       "4                     E              I             I5              D   \n",
       "...                 ...            ...            ...            ...   \n",
       "580546                E              F        unknown              C   \n",
       "580547                E              F        unknown              C   \n",
       "580548                E              F        unknown              C   \n",
       "580549                E              F        unknown              C   \n",
       "580550                E              F        unknown              C   \n",
       "\n",
       "        ListingInfo  Listinginfo1    LogInfo3  \n",
       "0          2014/3/5    2014-03-05  2014-02-20  \n",
       "1          2014/3/5    2014-03-05  2014-02-23  \n",
       "2          2014/3/5    2014-03-05  2014-02-24  \n",
       "3          2014/3/5    2014-03-05  2014-02-25  \n",
       "4          2014/3/5    2014-03-05  2014-02-27  \n",
       "...             ...           ...         ...  \n",
       "580546     2014/3/5    2014-03-05  2014-02-20  \n",
       "580547     2014/3/5    2014-03-05  2014-02-20  \n",
       "580548     2014/3/5    2014-03-05  2014-02-20  \n",
       "580549     2014/3/5    2014-03-05  2014-03-05  \n",
       "580550     2014/3/5    2014-03-05  2014-03-05  \n",
       "\n",
       "[580551 rows x 232 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>UserInfo_1</th>\n",
       "      <th>UserInfo_3</th>\n",
       "      <th>WeblogInfo_1</th>\n",
       "      <th>WeblogInfo_2</th>\n",
       "      <th>WeblogInfo_3</th>\n",
       "      <th>WeblogInfo_4</th>\n",
       "      <th>WeblogInfo_5</th>\n",
       "      <th>WeblogInfo_6</th>\n",
       "      <th>WeblogInfo_7</th>\n",
       "      <th>...</th>\n",
       "      <th>Education_Info4</th>\n",
       "      <th>Education_Info6</th>\n",
       "      <th>Education_Info7</th>\n",
       "      <th>Education_Info8</th>\n",
       "      <th>WeblogInfo_19</th>\n",
       "      <th>WeblogInfo_20</th>\n",
       "      <th>WeblogInfo_21</th>\n",
       "      <th>ListingInfo</th>\n",
       "      <th>Listinginfo1</th>\n",
       "      <th>LogInfo3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>I</td>\n",
       "      <td>I5</td>\n",
       "      <td>D</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580546</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>F</td>\n",
       "      <td>unknown</td>\n",
       "      <td>C</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580547</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>F</td>\n",
       "      <td>unknown</td>\n",
       "      <td>C</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580548</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>F</td>\n",
       "      <td>unknown</td>\n",
       "      <td>C</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-02-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580549</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>F</td>\n",
       "      <td>unknown</td>\n",
       "      <td>C</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-03-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580550</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>E</td>\n",
       "      <td>F</td>\n",
       "      <td>unknown</td>\n",
       "      <td>C</td>\n",
       "      <td>2014/3/5</td>\n",
       "      <td>2014-03-05</td>\n",
       "      <td>2014-03-05</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>580551 rows × 232 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 25
  },
  {
   "cell_type": "code",
   "id": "121efb05-2a19-4330-8e53-8f012f6cbf1f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:11.174847Z",
     "start_time": "2024-09-26T13:31:10.767980Z"
    }
   },
   "source": [
    "df_train.isnull().sum()"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Idx              0\n",
       "UserInfo_1       0\n",
       "UserInfo_3       0\n",
       "WeblogInfo_1     0\n",
       "WeblogInfo_2     0\n",
       "                ..\n",
       "WeblogInfo_20    0\n",
       "WeblogInfo_21    0\n",
       "ListingInfo      0\n",
       "Listinginfo1     0\n",
       "LogInfo3         0\n",
       "Length: 232, dtype: int64"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 26
  },
  {
   "cell_type": "code",
   "id": "e5f97d8b-66ba-41f7-aaee-b85b6c6ed15a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:19.712598Z",
     "start_time": "2024-09-26T13:31:17.980793Z"
    }
   },
   "source": [
    "from sklearn.preprocessing import LabelEncoder\n",
    "# 创建 LabelEncoder 实例\n",
    "label_encoder = LabelEncoder()\n",
    "\n",
    "# 将字符串列转换为数值\n",
    "for col in df_train.select_dtypes(include=['object']).columns:\n",
    "    df_train[col] = label_encoder.fit_transform(df_train[col])\n",
    "\n",
    "print(\"转换后的数据框：\")\n",
    "print(df_train)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "转换后的数据框：\n",
      "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
      "0       10001         1.0         4.0           1.0           1.0   \n",
      "1       10001         1.0         4.0           1.0           1.0   \n",
      "2       10001         1.0         4.0           1.0           1.0   \n",
      "3       10001         1.0         4.0           1.0           1.0   \n",
      "4       10001         1.0         4.0           1.0           1.0   \n",
      "...       ...         ...         ...           ...           ...   \n",
      "580546   9998         4.0         5.0           1.0           0.0   \n",
      "580547   9998         4.0         5.0           1.0           0.0   \n",
      "580548   9998         4.0         5.0           1.0           0.0   \n",
      "580549   9998         4.0         5.0           1.0           0.0   \n",
      "580550   9998         4.0         5.0           1.0           0.0   \n",
      "\n",
      "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
      "0                0.0           1.0           1.0           1.0            14   \n",
      "1                0.0           1.0           1.0           1.0            14   \n",
      "2                0.0           1.0           1.0           1.0            14   \n",
      "3                0.0           1.0           1.0           1.0            14   \n",
      "4                0.0           1.0           1.0           1.0            14   \n",
      "...              ...           ...           ...           ...           ...   \n",
      "580546           0.0           1.0           1.0           1.0             3   \n",
      "580547           0.0           1.0           1.0           1.0             3   \n",
      "580548           0.0           1.0           1.0           1.0             3   \n",
      "580549           0.0           1.0           1.0           1.0             3   \n",
      "580550           0.0           1.0           1.0           1.0             3   \n",
      "\n",
      "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
      "0       ...                2                4                0   \n",
      "1       ...                2                4                0   \n",
      "2       ...                2                4                0   \n",
      "3       ...                2                4                0   \n",
      "4       ...                2                4                0   \n",
      "...     ...              ...              ...              ...   \n",
      "580546  ...                2                4                0   \n",
      "580547  ...                2                4                0   \n",
      "580548  ...                2                4                0   \n",
      "580549  ...                2                4                0   \n",
      "580550  ...                2                4                0   \n",
      "\n",
      "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
      "0                     2              5             30              3   \n",
      "1                     2              5             30              3   \n",
      "2                     2              5             30              3   \n",
      "3                     2              5             30              3   \n",
      "4                     2              5             30              3   \n",
      "...                 ...            ...            ...            ...   \n",
      "580546                2              2             36              2   \n",
      "580547                2              2             36              2   \n",
      "580548                2              2             36              2   \n",
      "580549                2              2             36              2   \n",
      "580550                2              2             36              2   \n",
      "\n",
      "        ListingInfo  Listinginfo1  LogInfo3  \n",
      "0               159            98      1086  \n",
      "1               159            98      1089  \n",
      "2               159            98      1090  \n",
      "3               159            98      1091  \n",
      "4               159            98      1093  \n",
      "...             ...           ...       ...  \n",
      "580546          159            98      1086  \n",
      "580547          159            98      1086  \n",
      "580548          159            98      1086  \n",
      "580549          159            98      1099  \n",
      "580550          159            98      1099  \n",
      "\n",
      "[580551 rows x 232 columns]\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "cell_type": "code",
   "id": "478032c7-9695-4af5-bfdd-e07a6e8a0ac5",
   "metadata": {},
   "source": [
    "df_train"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "ae38dddb-ff58-465e-8dd8-34fdcb3ae119",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:24.998435Z",
     "start_time": "2024-09-26T13:31:23.526919Z"
    }
   },
   "source": [
    "from sklearn.preprocessing import LabelEncoder\n",
    "# 创建 LabelEncoder 实例\n",
    "label_encoder = LabelEncoder()\n",
    "\n",
    "# 将字符串列转换为数值\n",
    "for col in df_test.select_dtypes(include=['object']).columns:\n",
    "    df_test[col] = label_encoder.fit_transform(df_test[col])\n",
    "\n",
    "print(\"转换后的数据框：\")\n",
    "print(df_test)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "转换后的数据框：\n",
      "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
      "0       10005         1.0         5.0           1.0           0.0   \n",
      "1       10005         1.0         5.0           1.0           0.0   \n",
      "2       10005         1.0         5.0           1.0           0.0   \n",
      "3       10005         1.0         5.0           1.0           0.0   \n",
      "4       10013         4.0         6.0           1.0           0.0   \n",
      "...       ...         ...         ...           ...           ...   \n",
      "385875   9994         4.0         5.0           1.0           0.0   \n",
      "385876   9994         4.0         5.0           1.0           0.0   \n",
      "385877   9994         4.0         5.0           1.0           0.0   \n",
      "385878   9994         4.0         5.0           1.0           0.0   \n",
      "385879   9994         4.0         5.0           1.0           0.0   \n",
      "\n",
      "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
      "0                1.0           1.0           1.0           1.0             2   \n",
      "1                1.0           1.0           1.0           1.0             2   \n",
      "2                1.0           1.0           1.0           1.0             2   \n",
      "3                1.0           1.0           1.0           1.0             2   \n",
      "4                1.0           1.0           1.0           1.0             8   \n",
      "...              ...           ...           ...           ...           ...   \n",
      "385875           1.0           1.0           1.0           1.0             4   \n",
      "385876           1.0           1.0           1.0           1.0             4   \n",
      "385877           1.0           1.0           1.0           1.0             4   \n",
      "385878           1.0           1.0           1.0           1.0             4   \n",
      "385879           1.0           1.0           1.0           1.0             4   \n",
      "\n",
      "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
      "0       ...                2                4                0   \n",
      "1       ...                2                4                0   \n",
      "2       ...                2                4                0   \n",
      "3       ...                2                4                0   \n",
      "4       ...                2                4                0   \n",
      "...     ...              ...              ...              ...   \n",
      "385875  ...                2                4                0   \n",
      "385876  ...                2                4                0   \n",
      "385877  ...                2                4                0   \n",
      "385878  ...                2                4                0   \n",
      "385879  ...                2                4                0   \n",
      "\n",
      "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
      "0                     2              0             27              0   \n",
      "1                     2              0             27              0   \n",
      "2                     2              0             27              0   \n",
      "3                     2              0             27              0   \n",
      "4                     2              4             26              3   \n",
      "...                 ...            ...            ...            ...   \n",
      "385875                2              4             27              3   \n",
      "385876                2              4             27              3   \n",
      "385877                2              4             27              3   \n",
      "385878                2              4             27              3   \n",
      "385879                2              4             27              3   \n",
      "\n",
      "        ListingInfo  Listinginfo1  LogInfo3  \n",
      "0               142            84       963  \n",
      "1               142            84       964  \n",
      "2               142            84       963  \n",
      "3               142            84       963  \n",
      "4               223            91       968  \n",
      "...             ...           ...       ...  \n",
      "385875          223            91       971  \n",
      "385876          223            91       963  \n",
      "385877          223            91       963  \n",
      "385878          223            91       963  \n",
      "385879          223            91       963  \n",
      "\n",
      "[385880 rows x 231 columns]\n"
     ]
    }
   ],
   "execution_count": 28
  },
  {
   "cell_type": "code",
   "id": "4cbfe007-d484-41ae-85f9-82bfd646cee5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:27.504805Z",
     "start_time": "2024-09-26T13:31:27.384286Z"
    }
   },
   "source": [
    "df_test"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
       "0       10005         1.0         5.0           1.0           0.0   \n",
       "1       10005         1.0         5.0           1.0           0.0   \n",
       "2       10005         1.0         5.0           1.0           0.0   \n",
       "3       10005         1.0         5.0           1.0           0.0   \n",
       "4       10013         4.0         6.0           1.0           0.0   \n",
       "...       ...         ...         ...           ...           ...   \n",
       "385875   9994         4.0         5.0           1.0           0.0   \n",
       "385876   9994         4.0         5.0           1.0           0.0   \n",
       "385877   9994         4.0         5.0           1.0           0.0   \n",
       "385878   9994         4.0         5.0           1.0           0.0   \n",
       "385879   9994         4.0         5.0           1.0           0.0   \n",
       "\n",
       "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
       "0                1.0           1.0           1.0           1.0             2   \n",
       "1                1.0           1.0           1.0           1.0             2   \n",
       "2                1.0           1.0           1.0           1.0             2   \n",
       "3                1.0           1.0           1.0           1.0             2   \n",
       "4                1.0           1.0           1.0           1.0             8   \n",
       "...              ...           ...           ...           ...           ...   \n",
       "385875           1.0           1.0           1.0           1.0             4   \n",
       "385876           1.0           1.0           1.0           1.0             4   \n",
       "385877           1.0           1.0           1.0           1.0             4   \n",
       "385878           1.0           1.0           1.0           1.0             4   \n",
       "385879           1.0           1.0           1.0           1.0             4   \n",
       "\n",
       "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
       "0       ...                2                4                0   \n",
       "1       ...                2                4                0   \n",
       "2       ...                2                4                0   \n",
       "3       ...                2                4                0   \n",
       "4       ...                2                4                0   \n",
       "...     ...              ...              ...              ...   \n",
       "385875  ...                2                4                0   \n",
       "385876  ...                2                4                0   \n",
       "385877  ...                2                4                0   \n",
       "385878  ...                2                4                0   \n",
       "385879  ...                2                4                0   \n",
       "\n",
       "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
       "0                     2              0             27              0   \n",
       "1                     2              0             27              0   \n",
       "2                     2              0             27              0   \n",
       "3                     2              0             27              0   \n",
       "4                     2              4             26              3   \n",
       "...                 ...            ...            ...            ...   \n",
       "385875                2              4             27              3   \n",
       "385876                2              4             27              3   \n",
       "385877                2              4             27              3   \n",
       "385878                2              4             27              3   \n",
       "385879                2              4             27              3   \n",
       "\n",
       "        ListingInfo  Listinginfo1  LogInfo3  \n",
       "0               142            84       963  \n",
       "1               142            84       964  \n",
       "2               142            84       963  \n",
       "3               142            84       963  \n",
       "4               223            91       968  \n",
       "...             ...           ...       ...  \n",
       "385875          223            91       971  \n",
       "385876          223            91       963  \n",
       "385877          223            91       963  \n",
       "385878          223            91       963  \n",
       "385879          223            91       963  \n",
       "\n",
       "[385880 rows x 231 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>UserInfo_1</th>\n",
       "      <th>UserInfo_3</th>\n",
       "      <th>WeblogInfo_1</th>\n",
       "      <th>WeblogInfo_2</th>\n",
       "      <th>WeblogInfo_3</th>\n",
       "      <th>WeblogInfo_4</th>\n",
       "      <th>WeblogInfo_5</th>\n",
       "      <th>WeblogInfo_6</th>\n",
       "      <th>WeblogInfo_7</th>\n",
       "      <th>...</th>\n",
       "      <th>Education_Info4</th>\n",
       "      <th>Education_Info6</th>\n",
       "      <th>Education_Info7</th>\n",
       "      <th>Education_Info8</th>\n",
       "      <th>WeblogInfo_19</th>\n",
       "      <th>WeblogInfo_20</th>\n",
       "      <th>WeblogInfo_21</th>\n",
       "      <th>ListingInfo</th>\n",
       "      <th>Listinginfo1</th>\n",
       "      <th>LogInfo3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "      <td>964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10005</td>\n",
       "      <td>1.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>142</td>\n",
       "      <td>84</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10013</td>\n",
       "      <td>4.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>8</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>26</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>968</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385875</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>971</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385876</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385877</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385878</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>385879</th>\n",
       "      <td>9994</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>27</td>\n",
       "      <td>3</td>\n",
       "      <td>223</td>\n",
       "      <td>91</td>\n",
       "      <td>963</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>385880 rows × 231 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 29
  },
  {
   "cell_type": "code",
   "id": "6a8731a9-ea1f-480e-bf81-2610157eb561",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:31:53.006591Z",
     "start_time": "2024-09-26T13:31:50.727882Z"
    }
   },
   "source": [
    "import xgboost as xgb\n",
    "from sklearn.model_selection import train_test_split\n",
    "X = df_train.loc[:,df_train.columns != 'target']  # 数据\n",
    "y = df_train.loc[:,df_train.columns == 'target']  # 标签\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
    "X"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "          Idx  UserInfo_1  UserInfo_3  WeblogInfo_1  WeblogInfo_2  \\\n",
       "0       10001         1.0         4.0           1.0           1.0   \n",
       "1       10001         1.0         4.0           1.0           1.0   \n",
       "2       10001         1.0         4.0           1.0           1.0   \n",
       "3       10001         1.0         4.0           1.0           1.0   \n",
       "4       10001         1.0         4.0           1.0           1.0   \n",
       "...       ...         ...         ...           ...           ...   \n",
       "580546   9998         4.0         5.0           1.0           0.0   \n",
       "580547   9998         4.0         5.0           1.0           0.0   \n",
       "580548   9998         4.0         5.0           1.0           0.0   \n",
       "580549   9998         4.0         5.0           1.0           0.0   \n",
       "580550   9998         4.0         5.0           1.0           0.0   \n",
       "\n",
       "        WeblogInfo_3  WeblogInfo_4  WeblogInfo_5  WeblogInfo_6  WeblogInfo_7  \\\n",
       "0                0.0           1.0           1.0           1.0            14   \n",
       "1                0.0           1.0           1.0           1.0            14   \n",
       "2                0.0           1.0           1.0           1.0            14   \n",
       "3                0.0           1.0           1.0           1.0            14   \n",
       "4                0.0           1.0           1.0           1.0            14   \n",
       "...              ...           ...           ...           ...           ...   \n",
       "580546           0.0           1.0           1.0           1.0             3   \n",
       "580547           0.0           1.0           1.0           1.0             3   \n",
       "580548           0.0           1.0           1.0           1.0             3   \n",
       "580549           0.0           1.0           1.0           1.0             3   \n",
       "580550           0.0           1.0           1.0           1.0             3   \n",
       "\n",
       "        ...  Education_Info4  Education_Info6  Education_Info7  \\\n",
       "0       ...                2                4                0   \n",
       "1       ...                2                4                0   \n",
       "2       ...                2                4                0   \n",
       "3       ...                2                4                0   \n",
       "4       ...                2                4                0   \n",
       "...     ...              ...              ...              ...   \n",
       "580546  ...                2                4                0   \n",
       "580547  ...                2                4                0   \n",
       "580548  ...                2                4                0   \n",
       "580549  ...                2                4                0   \n",
       "580550  ...                2                4                0   \n",
       "\n",
       "        Education_Info8  WeblogInfo_19  WeblogInfo_20  WeblogInfo_21  \\\n",
       "0                     2              5             30              3   \n",
       "1                     2              5             30              3   \n",
       "2                     2              5             30              3   \n",
       "3                     2              5             30              3   \n",
       "4                     2              5             30              3   \n",
       "...                 ...            ...            ...            ...   \n",
       "580546                2              2             36              2   \n",
       "580547                2              2             36              2   \n",
       "580548                2              2             36              2   \n",
       "580549                2              2             36              2   \n",
       "580550                2              2             36              2   \n",
       "\n",
       "        ListingInfo  Listinginfo1  LogInfo3  \n",
       "0               159            98      1086  \n",
       "1               159            98      1089  \n",
       "2               159            98      1090  \n",
       "3               159            98      1091  \n",
       "4               159            98      1093  \n",
       "...             ...           ...       ...  \n",
       "580546          159            98      1086  \n",
       "580547          159            98      1086  \n",
       "580548          159            98      1086  \n",
       "580549          159            98      1099  \n",
       "580550          159            98      1099  \n",
       "\n",
       "[580551 rows x 231 columns]"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Idx</th>\n",
       "      <th>UserInfo_1</th>\n",
       "      <th>UserInfo_3</th>\n",
       "      <th>WeblogInfo_1</th>\n",
       "      <th>WeblogInfo_2</th>\n",
       "      <th>WeblogInfo_3</th>\n",
       "      <th>WeblogInfo_4</th>\n",
       "      <th>WeblogInfo_5</th>\n",
       "      <th>WeblogInfo_6</th>\n",
       "      <th>WeblogInfo_7</th>\n",
       "      <th>...</th>\n",
       "      <th>Education_Info4</th>\n",
       "      <th>Education_Info6</th>\n",
       "      <th>Education_Info7</th>\n",
       "      <th>Education_Info8</th>\n",
       "      <th>WeblogInfo_19</th>\n",
       "      <th>WeblogInfo_20</th>\n",
       "      <th>WeblogInfo_21</th>\n",
       "      <th>ListingInfo</th>\n",
       "      <th>Listinginfo1</th>\n",
       "      <th>LogInfo3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1089</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1090</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10001</td>\n",
       "      <td>1.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>14</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>30</td>\n",
       "      <td>3</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580546</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580547</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580548</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1086</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580549</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>580550</th>\n",
       "      <td>9998</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>36</td>\n",
       "      <td>2</td>\n",
       "      <td>159</td>\n",
       "      <td>98</td>\n",
       "      <td>1099</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>580551 rows × 231 columns</p>\n",
       "</div>"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 31
  },
  {
   "cell_type": "code",
   "id": "6d4cf6af-33ab-44e3-b6aa-7df37645442f",
   "metadata": {},
   "source": [
    "# 创建和训练 XGBoost 模型\n",
    "model = xgb.XGBClassifier()\n",
    "model.fit(X_train, y_train)\n",
    "\n",
    "# 获取特征重要性\n",
    "importance = model.feature_importances_\n",
    "\n",
    "# 创建 DataFrame 以便于查看\n",
    "importance_df = pd.DataFrame({'Feature': X.columns, 'Importance': importance})\n",
    "importance_df = importance_df.sort_values(by='Importance', ascending=False).head(50)\n",
    "\n",
    "# 打印特征重要性\n",
    "print(importance_df)\n",
    "\n",
    "# 可视化特征重要性\n",
    "plt.figure(figsize=(10, 6))\n",
    "plt.barh(importance_df['Feature'], importance_df['Importance'])\n",
    "plt.xlabel('Importance')\n",
    "plt.title('Feature Importance from XGBoost')\n",
    "plt.show()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "64d8441d5b2c8624",
   "metadata": {},
   "source": [
    "# 特征选择\n",
    "# 卡方\n",
    "from sklearn.feature_selection import SelectKBest, chi2\n",
    "import sklearn\n",
    "XX= sklearn.preprocessing.MinMaxScaler().fit_transform(X)\n",
    "chi2_selector = SelectKBest(chi2, k=2)\n",
    "X_kbest = chi2_selector.fit_transform(XX, y)\n",
    "X_kbest"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "569493f5-2a94-46a7-bba5-e1e1bd024d5a",
   "metadata": {},
   "source": [
    "# # 使用递归特征消除（RFE）\n",
    "# from sklearn.feature_selection import RFE\n",
    "# from sklearn.linear_model import LogisticRegression\n",
    "# # 使用逻辑回归进行递归特征消除\n",
    "# model = LogisticRegression()\n",
    "# rfe = RFE(model, n_features_to_select=2)\n",
    "# fit = rfe.fit(X, y)\n",
    "\n",
    "# print(\"选择的特征索引：\", fit.support_)\n",
    "# print(\"特征排名：\", fit.ranking_)"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "b6e4f785-8e9c-48f5-a052-6eaa795fe562",
   "metadata": {},
   "source": [
    "# 降维\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "# 标准化数据\n",
    "scaler = StandardScaler()\n",
    "scaled_data = scaler.fit_transform(df_train)\n",
    "\n",
    "# 使用 PCA 降维\n",
    "pca = PCA(n_components=2)\n",
    "reduced_data = pca.fit_transform(scaled_data)\n",
    "\n",
    "# 创建 DataFrame 并查看结果\n",
    "reduced_df = pd.DataFrame(data=reduced_data, columns=['PC1', 'PC2'])\n",
    "print(reduced_df)\n",
    "\n",
    "# 可视化降维后的数据\n",
    "plt.scatter(reduced_df['PC1'], reduced_df['PC2'])\n",
    "plt.xlabel('Principal Component 1')\n",
    "plt.ylabel('Principal Component 2')\n",
    "plt.title('PCA Result')\n",
    "plt.show()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "d8b15139-d22e-47d4-a773-ed64da8d28c3",
   "metadata": {},
   "source": [
    "reduced_data"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "7172f704-04cc-4b07-a0d2-ff5e57096bfc",
   "metadata": {},
   "source": [
    "# from sklearn.discriminant_analysis import LinearDiscriminantAnalysis as LDA\n",
    "# # 创建 LDA 实例\n",
    "# lda = LDA(n_components=2)  # 降维到 2 维\n",
    "\n",
    "# # 拟合模型并进行转换\n",
    "# X_lda = lda.fit_transform(X, y)\n",
    "\n",
    "# # 将结果转换为 DataFrame，便于可视化\n",
    "# lda_df = pd.DataFrame(data=X_lda, columns=['LD1', 'LD2'])\n",
    "# lda_df['target'] = y\n",
    "\n",
    "# # 可视化结果\n",
    "# colors = ['red', 'green', 'blue']\n",
    "# targets = np.unique(y)\n",
    "\n",
    "# plt.figure(figsize=(8, 6))\n",
    "# for target, color in zip(targets, colors):\n",
    "#     plt.scatter(lda_df[lda_df['target'] == target]['LD1'], \n",
    "#                 lda_df[lda_df['target'] == target]['LD2'], \n",
    "#                 label=data.target_names[target], \n",
    "#                 color=color)\n",
    "# plt.title('LDA: Linear Discriminant Analysis')\n",
    "# plt.xlabel('LD1')\n",
    "# plt.ylabel('LD2')\n",
    "# plt.legend()\n",
    "# plt.grid()\n",
    "# plt.show()"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "03d7b7ea-3e5d-4835-8904-8f88ea8c40e1",
   "metadata": {},
   "source": [
    "print(\"2\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "655f7aa4-5039-4724-940a-2943b85ea271",
   "metadata": {},
   "source": [
    "# from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.metrics import roc_auc_score, roc_curve\n",
    "# # 创建逻辑回归模型\n",
    "# model = LogisticRegression()\n",
    "\n",
    "# # 训练模型\n",
    "# model.fit(X_train, y_train)\n",
    "# # 预测概率\n",
    "# y_pred = model.predict_proba(X_test)[:,1]\n",
    "# # 计算 AUC 值\n",
    "# # auc_value = roc_auc_score(y_test, y_pred)\n",
    "# # print(f\"AUC 值: {auc_value}\")"
   ],
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "id": "9a977ac0-dd52-4b03-a1cb-42dac06111dd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-09-26T13:36:35.535848Z",
     "start_time": "2024-09-26T13:31:58.869997Z"
    }
   },
   "source": [
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.metrics import accuracy_score\n",
    "# 随机森林分类器\n",
    "rf = RandomForestClassifier()\n",
    "# 拟合数据集\n",
    "clf = rf.fit(X_train, y_train.values.ravel())\n",
    "# 预测测试集\n",
    "y_pred = clf.predict(X_test)\n",
    "y_auc = roc_auc_score(y_test,y_pred)\n",
    "y_auc\n",
    "print(f'AUC: {y_auc}')"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AUC: 0.9999445860578522\n"
     ]
    }
   ],
   "execution_count": 32
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
